package me.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 
 * @author guanpanpan
 *
 */
public class SpeedCompare {
	public static void main(String[] args) {
		final int testCount = 100000;
		final int findCount = 10000;
		List<Stu> stuList = new ArrayList<Stu>();
		Set<Stu> stusSet = new HashSet<Stu>();
		Map<String, Stu> stusMap = new HashMap<String, Stu>();

		long sTime = System.currentTimeMillis();
		for (int i = 0; i < testCount; i++) {
			String s = "" + i;
			stusMap.put("" + i, new Stu("" + i));
		}
		System.out.println("addToMap" + testCount + ":" + (System.currentTimeMillis() - sTime));

		sTime = System.currentTimeMillis();
		for (int i = 0; i < testCount; i++) {
			stuList.add(new Stu("" + i));
		}
		System.out.println("addToList" + testCount + ":" + (System.currentTimeMillis() - sTime));

		sTime = System.currentTimeMillis();
		for (int i = 0; i < testCount; i++) {
			stusSet.add(new Stu("" + i));
		}
		System.out.println("addToSet" + testCount + ":" + (System.currentTimeMillis() - sTime));

		sTime = System.currentTimeMillis();
		for (int i = 0; i < findCount; i++) {
			stuList.contains("" + i);
		}
		System.out.println("containsByList" + testCount + ":" + (System.currentTimeMillis() - sTime));

		sTime = System.currentTimeMillis();
		for (int i = 0; i < findCount; i++) {
			stusSet.contains("" + i);
		}
		System.out.println("containsBySet" + testCount + ":" + (System.currentTimeMillis() - sTime));

		sTime = System.currentTimeMillis();
		for (int i = 0; i < findCount; i++) {
			stusMap.get("" + i);
		}
		System.out.println("getByMap" + testCount + ":" + (System.currentTimeMillis() - sTime));

	}
}

class Stu {
	public Stu(String name) {
		this.name = name;
	}

	private String name;
}
